import { ref, shallowRef, defineAsyncComponent } from 'vue'


export default {
    install: async function (app) {

        app.on('AfterPluginload', () => {
            const AddConfig = app.GetPluginEvent('App.AddConfig')
            AddConfig({
                type: 'custome',
                AddButtonComp: shallowRef(defineAsyncComponent(() => import('./View/AddButton.vue'))),
                TreeComp: shallowRef(defineAsyncComponent(() => import('./View/TreeComp.vue'))),
                ContentComp: shallowRef(defineAsyncComponent(() => import('./View/ContentComp.vue'))),
                TitleRightComp: shallowRef(defineAsyncComponent(() => import('./View/TitleRightComp.vue'))),
            })
        });

        app.AddRouter([{
            path: '/Custom/Designer/app-:appId(.*)/form-:formId(.*)',
            name: 'Custom-Designer',
            component: () => import('./Editor/Designer.vue'),
        }, {
            path: '/Custom/Setting/app-:appId(.*)/form-:formId(.*)',
            name: 'Custom-Setting',
            component: () => import('./Editor/Setting.vue'),
        }]);



        const modules = import.meta.glob('./Cell/*/index.js');
        const RegistCell = app.GetPluginEvent('VisualEditor-Core.RegistCell');
        app.on('VisualEditor-Core.Runing', () => {
            for (const key in modules) {
                const element = modules[key];
                const _key = key.replace('./Cell/', '').replace('/index.js', '')
                RegistCell(_key, element());
            }
        })
    }
}